var vm = new Vue({
    //vue对象节点,指向父盒子
    el:'#letter',                                                            
    //vue实例 的data属性
    data:function(){
        return{
        	pageA:true,
        	tableData:[],
        	newFlag:false,
        	//分页条
  	        pageSize:10,
  	        currPage:1,
  	        total:1,
  	        lostEditorEdit:null,
  	        //
  	        flag:false,
  	        lostTopic:{},
  	        //帖子详情
  	        topic:{},
  	        topicV:false,
  	        topicData:{
  	    	  "user":{},
  	    	  "plate":{},
  	    	  "topic":{}
  	        }
        }
    },
    //vue实例 的methods
    methods:{
    	handleSizeChange:function(val) {
            vm.pageSize = val;
            vm.loadData();
         },
         handleCurrentChange:function(val) {
      	   vm.currPage = val;
      	   vm.loadData();
         },
         //格式化日期
         dateFormat:function(row,column){
      	   var date = row[column.property];
      	   if(date == undefined){
      		   return "";
      	   }
      	   return moment(date).format("YYYY-MM-DD HH:mm:ss");
         },
         loadData:function(){
      	   vm.lostEditorEdit = UM.getEditor("lostEditorEdit");
      	   $('.edui-container').css("width","");
      	   $('.edui-container').css("height","600px");
      	   $('.edui-body-container').css("width","");
      	   
      	   if(pb.getQueryString('id') == 'admin'){
      		   vm.flag = true;
      	   }else{
      		   vm.flag = false;
      	   }
      	   
      	   var url = "./listThanksByPage.action";
     
      	   var params = {
      			"pagemap.page":vm.currPage,
                "pagemap.size":vm.pageSize 
      	   }
      	   pb.ajaxPost(url,params,function(r){
  	       		if(r.code == '000000'){
  	       			vm.tableData = r.thanksLetters;
  	       			var nowDate = new Date().getTime();
  	       			if(vm.tableData !== null && vm.tableData.length>0){
  	       				for(var i=0;i<vm.tableData.length;i++){
  	       					var tempDate = new Date(vm.tableData[i].l_create_time).getTime();
  	       					vm.tableData[i].flag = nowDate - tempDate > (1 * 3600 * 1000 * 24)?0:1;
  	       					
  	       					vm.lostEditorEdit.setContent(vm.tableData[i].lcontent);
  	       					vm.tableData[i].lcontent = vm.lostEditorEdit.getContentTxt();
  		       			}
  	       			}
  	       			vm.lostEditorEdit.setContent('');
  	       			vm.total = r.thankscount;
  	       		}else{
                 		pb.alertErr("加载失败");
                 	}
  	       },function(err){
  	    	   pb.alertErr("加载失败");
  	       });
         },
         getRecord(tid){
      	   var url = "./selectLetterByPrimary.action";
      	   var params = {
      		   'topic.tid':tid
      	   }
      	   pb.ajaxPost(url,params,function(r){
  	       		if(r.code == '000000'){
  	       			vm.topicData = r.topic;
  	       			vm.lostEditorEdit.setContent(vm.topicData.tcontent);
  	       			vm.topicData.createDate = moment(vm.topicData.t_create_time).format('YYYY-MM-DD');
  	       			vm.topicData.tcontent = vm.lostEditorEdit.getContent();
  	       			$('#content').append(vm.topicData.tcontent);
  	       			//vm.lostEditorEdit.setContent('');
  	       		}else{
  	       		 pb.alertErr('获取信息失败');
  	       		}
  	       },function(err){
  	    	   pb.alertErr('获取信息失败');
  	       });
         },
         open(tid){
      	   /*$('#content').empty();
      	   vm.topicV = true;
      	   vm.getRecord(tid);*/
           window.parent.vm.goTo('viewLetter',tid);
         },
       //删除
         del:function(tid){
      	   var ids = [];
      	   ids.push(tid);
      	   vm.$confirm('确定删除么?','提示',{
                 confirmButtonText: '确定',
                 cancelButtonText: '取消',
                 type:'warning',
                 callback:function(e){
                     if(e === 'confirm'){
                  	   var params = {
                  		   "res.ids":JSON.stringify(ids)
                  	   }
                         pb.ajaxPost("./deleteLetter.action",params,function(res){
                             if(res.code == '000000'){
                          	   pb.alertSuc('删除成功');
                               vm.loadData();
                             }else{
                             	pb.alertErr('删除失败');
                             }
                         });
                     	
                     }
                 }
             });
         }

    }
    //vue实例 的methods结束
});
vm.loadData();